package com.fpx.order.plat.common.utils;

import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;

import org.apache.commons.lang.StringUtils;

public class CacheUtil {
	
	public static void main(String[] args){
		System.out.println(StringUtils.isEmpty("111"));
		
	}
	
    /**
     * 获取缓存
     * 
     * @param key
     * @return
     */
    @SuppressWarnings("unchecked")
	public static <T> T getCache(String key) {
        if (!StringUtils.isEmpty(key)) {
            Cache objCache = CacheInstance.getInstatnce();
            Element objElement = objCache.get(key);
            if (objElement != null) {
                Object obj = objElement.getObjectValue();
                if (obj != null) {
                    return (T) obj;
                }
            }
        }
        return null;
    }

    /**
     * 保存缓存
     * @param key
     * @param value
     */
    public static <T> void setCache(String key, T value) {
        if (!StringUtils.isEmpty(key) && value != null) {
            Cache objCache = CacheInstance.getInstatnce();
            Element objElement = new Element(key, value);
            objCache.put(objElement);
        }
    }
}
